﻿using AutoRetailsEXE;
using CefSharp;
using CefSharp.WinForms;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;


namespace AutoRetailsDLL.Workers.PinDuoDuo
{
    public class PinDuoDuoWorker: WorkersBase
    {
        private string web_url = "https://mms.pinduoduo.com/goods/category";
        private string web_login_url = "https://mms.pinduoduo.com";//"https://www.baidu.com/?tn=62095104_19_oem_dg";//"https://mms.pinduoduo.com/home/";
        private PinDuoDuoAddGoodModel_In param_in= null;
        private static string _count=string.Empty;
        private static string _password = string.Empty;
        private bool Is判断Login状态=false;
        //不可直接用
        private static bool Is登录 = false;
        public static PinDuoDuoWorker Instance = new PinDuoDuoWorker();

        public void InitPinDuoDuoAsync()
        {
            LogHelper.WriteLog($"InitPinDuoDuoAsync执行");
            chromePage.Show();
            GetChromiumWebBrowser().LoadUrl(web_url);
            WaitWebBrowserAsync(2000);
            WaitWebBrowserLoadingAsync();
            //设置上传文件事件
            SetUploadFileDialogHandler();
            GetChromiumWebBrowser().AddressChanged += PinDuoDuoWorker_AddressChanged;
            //await Login();
        }
        
        private void PinDuoDuoWorker_AddressChanged(object sender, AddressChangedEventArgs e)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)sender;
            var newAddress = chromiumWebBrowser.Address;
            if (Is判断Login状态&& newAddress.Contains("login"))
            {
                Is登录 = false;
            }
            Is登录 = true;
            // 在这里处理新的地址
            //System.Diagnostics.Debug.WriteLine($"New Address: {newAddress}");
        }
        
        public async Task<WorkResult> Login(string count,string password)
        {
            try {
                LogHelper.WriteLog($"开始登陆：{count}，{password}");
                InitPinDuoDuoAsync();
                执行必备JS();
                点击元素_左键(JavaScriptString.拼多多_账号登录JS,500);
                点击元素_输入(JavaScriptString.拼多多_账号输入框JS, count,500);
                点击元素_输入(JavaScriptString.拼多多_密码输入框JS, password, 500);
                点击元素_左键(JavaScriptString.拼多多_登录按钮JS, 500);
                for (int i = 0; i < 5; i++)
                {
                    if (IsLogin2())
                    {
                        result=WorkResult.WorkSuccess();
                        return result;
                    }
                    else
                    {
                        WaitWebBrowserAsync(1000);
                    }
                }
                result=WorkResult.WorkFailed();
                return result;
            } 
            catch (Exception ee)
            {
                LogHelper.WriteLog($"Login发生异常", ee);
                return WorkResult.WorkFailed();
            }
                     
        }
        public async Task<WorkResult> AddGood(string json,string configJson) 
        {
            result = new WorkResult();
            try
            {
                LogHelper.WriteLog($"AddGood入参：{json}");
                LogHelper.WriteLog($"AddGood配置入参：{configJson}");
                SetConfig(configJson);
                PinDuoDuoAddGoodModel_In pinDuoDuoAddGoodModel_In = JsonConvert.DeserializeObject<PinDuoDuoAddGoodModel_In>(json);
                param_in = pinDuoDuoAddGoodModel_In;
                AddGood();
                LogHelper.WriteLog($"任务结束出参：{JsonConvert.SerializeObject(result)}");
                return result;
            }
            catch (Exception ee)
            {
                LogHelper.WriteLog($"AddGood异常",ee);
                return WorkResult.WorkFailed($"AddGood异常:{ee}");
            }
           
        }
        public async Task<WorkResult> AddGood(PinDuoDuoAddGoodModel_In pinDuoDuoAddGoodModel_In, WorkerConfig workerConfig)
        {
            result = null;
            try
            {
                LogHelper.WriteLog($"AddGood入参：{JsonConvert.SerializeObject(pinDuoDuoAddGoodModel_In)}");
                LogHelper.WriteLog($"AddGood配置入参：{JsonConvert.SerializeObject(pinDuoDuoAddGoodModel_In)}");
                SetConfig(workerConfig);
                param_in = pinDuoDuoAddGoodModel_In;
                AddGood();
                LogHelper.WriteLog($"任务结束出参：{JsonConvert.SerializeObject(result)}");
                return result;
            }
            catch (Exception ee)
            {
                LogHelper.WriteLog($"AddGood异常", ee);
                return WorkResult.WorkFailed($"AddGood异常:{ee}");
            }

        }
        /// <summary>
        /// 通过刷新页面判断，更准确
        /// </summary>
        /// <returns></returns>
        public bool IsLogin()
        {
            Is判断Login状态=true;
            GetChromiumWebBrowser().LoadUrl(web_url);
            WaitWebBrowserLoadingAsync();
            WaitWebBrowserAsync(5000);
            LogHelper.WriteLog($"登录验证：{Is登录}");
            Is判断Login状态 = false;
            return Is登录;
        }
        /// <summary>
        /// 通过判断页面判断
        /// </summary>
        /// <returns></returns>
        public bool IsLogin2()
        {
            bool islogin=false;
            if (!GetChromiumWebBrowser().Address.Contains("login"))
            {
                islogin =true;
            }
            LogHelper.WriteLog($"登录验证：{islogin}");
            return islogin;
        }
        public void SetParam(PinDuoDuoAddGoodModel_In pinDuoDuoAddGoodModel_In)
        {
            param_in = pinDuoDuoAddGoodModel_In;
        }
        public WorkResult AddGood() 
        {
            bool login_result = IsLogin();
            if (!login_result)
            {               
                result = WorkResult.WorkFailed("请先登录");
                return result;
            }
            checkParamIn();

            执行必备JS();
            选择品类();
            if (endTime<DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
           上传轮播图();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            bool 属性填写_Result= 填写商品属性();
            if (!属性填写_Result)
            {
                return result;
            }
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            上传详情图();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            上传白底图();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            规格与库存();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            规格与库存2();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            服务与承诺();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            提交或保存();
            判断发布商品最终成功();
            return result;
        }
        public async Task<WorkResult> TestAddGood() 
        {
            //执行必备JS();
            //选择品类();
            //上传轮播图();
            填写商品属性();
            //上传详情图();
            //上传白底图();
            //规格与库存();
            //规格与库存2();
            //服务与承诺();
            //提交或保存();
            //判断发布商品最终成功();
            return result;
        }
        private string checkParamIn() 
        {
            return string.Empty;
        }
        public void 选择品类() 
        {
            LogHelper.WriteLog($"进入选择品类模块");
            if (Is快捷选择品类按钮())
            {
                LogHelper.WriteLog($"快捷选择品类");
                点击元素_左键(JavaScriptString.拼多多_快捷品类JS, listClickWaitTime);
                for (int i = 0; i < 50; i++)
                {
                    if (Is快捷选择品类是否被点击按钮())
                    {
                        LogHelper.WriteLog($"快捷选择品类成功");

                        点击元素_左键(JavaScriptString.拼多多_发布该类商品_按钮JS, listClickWaitTime);
                        result = WorkResult.WorkSuccess();
                        return;
                    }
                    else
                    {
                        点击元素_左键(JavaScriptString.拼多多_快捷品类JS, 500);
                    }
                }
                result=WorkResult.WorkFailed("寻找快捷品类失败");
            }
            else
            {
                LogHelper.WriteLog($"普通选择品类");
                点击元素_左键(JavaScriptString.拼多多_数码电器JS, listClickWaitTime);
                点击元素_左键(JavaScriptString.拼多多_3C数码配件JS, 1500);
                点击元素_左键(JavaScriptString.拼多多_手机配件JS, 1500);
                点击元素_左键(JavaScriptString.拼多多_手机保护套JS, 1500);
                点击元素_左键(JavaScriptString.拼多多_发布该类商品_按钮JS, wordWaitTime);
            }
            result = WorkResult.WorkSuccess(); 
        }
        
        private void 上传轮播图()
        {            
            LogHelper.WriteLog($"进入上传轮播图模块");
            WaitWebBrowserAsync(2000);
            List<string> file_path_list = param_in.materialFile.FirstOrDefault(n => n.materialType== "master").specList.Select(n=>n.imageName).ToList();// new List<string> { @"E:\谷歌下载\1.jpeg", @"E:\谷歌下载\2.jpeg", @"E:\谷歌下载\3.jpeg" };
            //SetUploadFilePath(file_path_list);
            点击元素_JS(JavaScriptString.拼多多_上传按钮JS, 2000);
            上传图片(file_path_list);
            result = WorkResult.WorkSuccess();
        }
        
        public bool 填写商品属性()
        {
            LogHelper.WriteLog($"进入填写商品属性模块");
            bool check_result=true;
            执行必备JS();

            //填写标题
            LogHelper.WriteLog($"填写标题");
            设置元素居中(JavaScriptString.拼多多_标题输入框JS);
            点击元素_输入(JavaScriptString.拼多多_标题输入框JS, param_in.onlineGoodsTitle,wordWaitTime);
            //填写品牌
            LogHelper.WriteLog($"填写品牌");
            check_result = 填写内容并选取("basic.propertys.0.value", param_in.brand);
            if (!check_result)
            {
                result=WorkResult.WorkFailed($"品牌：{param_in.brand}未找到");
                return false;
            }
            //填写适用品牌
            LogHelper.WriteLog($"填写适用品牌");
            check_result = 填写内容并选取("basic.propertys.1.value", param_in.modelCode.FirstOrDefault()?.pddApplyBrand);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"适用品牌：{param_in.modelCode.FirstOrDefault()?.pddApplyBrand}未找到");
                return false;
            }
            WaitWebBrowserAsync(1000);
            //填写适用型号
            LogHelper.WriteLog($"填写适用型号");
            点击内容("basic.propertys.6.value");
            foreach (var item in param_in.modelCode)
            {
                
                if (!Is选项存在(item.pddApplyModel))
                {
                    result = WorkResult.WorkFailed($"适用型号：{item.pddApplyModel}未找到");
                    return false;
                }
                WaitWebBrowserAsync(500);
                选择下拉元素_JS(item.pddApplyModel, wordWaitTime);
            }
            //填写保护套质地
            LogHelper.WriteLog($"填写保护套质地");
            check_result = 填写内容并选取("basic.propertys.2.value", param_in.goodsTexture);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"保护套质地：{param_in.goodsTexture}未找到");
                return false;
            }
            //填写款式
            LogHelper.WriteLog($"填写款式");
            check_result = 填写内容并选取("basic.propertys.3.value", param_in.goodsDesign);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"款式：{param_in.goodsDesign}未找到");
                return false;
            }
            //填写流行元素
            LogHelper.WriteLog($"填写流行元素");
            check_result = 填写内容并选取("basic.propertys.4.value", param_in.fashionElement);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"流行元素：{param_in.fashionElement}未找到");
                return false;
            }
            //填写风格
            LogHelper.WriteLog($"填写风格");
            check_result = 填写内容并选取("basic.propertys.5.value", param_in.goodsStyle);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"风格：{param_in.goodsStyle}未找到");
                return false;
            }
            点击屏幕();
            result = WorkResult.WorkSuccess();
            return true;
        }
        private void 上传详情图()
        {
            LogHelper.WriteLog($"上传详情图");
            设置元素居中2(JavaScriptString.拼多多_详情图上传JS);
            List<string> file_path_list = param_in.materialFile.FirstOrDefault(n => n.materialType == "detail").specList.Select(n => n.imageName).ToList();//new List<string> { @"E:\谷歌下载\1.jpeg", @"E:\谷歌下载\2.jpeg", @"E:\谷歌下载\3.jpeg" };
            //SetUploadFilePath(file_path_list);
            点击元素_JS(JavaScriptString.拼多多_详情图上传JS, 2000);
            上传图片(file_path_list);
            result= WorkResult.WorkSuccess();
        }
        private void 上传白底图()
        {
            LogHelper.WriteLog($"上传白底图");
            设置元素居中2(JavaScriptString.拼多多_白底图上传JS);
            List<string> file_path_list = param_in.materialFile.FirstOrDefault(n => n.materialType == "whiteBg").specList.Select(n => n.imageName).ToList();
            //SetUploadFilePath(file_path_list);
            点击元素_JS(JavaScriptString.拼多多_白底图上传JS, 2000);
            上传图片(file_path_list);
            result = WorkResult.WorkSuccess();
        }
        private void 规格与库存_ss()
        {
            LogHelper.WriteLog($"规格与库存");
            ExecuteScriptAndWaitAsync(JavaScriptString.拼多多_点击添加规格类型JS, 1000);
            string 点击并选择规格1js = @"document.getElementsByClassName(""goods-spec-row"")[0].getElementsByClassName(""IPT_input_5-126-0"")[0].click();
            getElementByText('li','{0}').click()";
            string 点击并选择规格2js = @"document.getElementsByClassName(""goods-spec-row"")[1].getElementsByClassName(""IPT_input_5-126-0"")[0].click();
            getElementByText('li','{0}').click()";
            string 输入规格1js= @"var ele= document.getElementsByClassName(""spec-input"")[{0}].getElementsByTagName(""input"")[0];setInputValue(ele,'{1}')";
            string 输入规格2js = @"var ele= document.getElementsByClassName(""spec-input"")[{0}].getElementsByTagName(""input"")[0];setInputValue(ele,'{1}')";
            string[] strings = param_in.specifications.Split('-');
            int input_index = 0;
            if (strings.Count()>0)
            {
                string js= string.Format(点击并选择规格1js, strings[0]);
                ExecuteScriptAndWaitAsync(js, wordWaitTime);
                for (int i = 0; i < param_in.spec1.Count; i++)
                {
                    string js2 = string.Format(输入规格1js, input_index, param_in.spec1[i]);
                    ExecuteScriptAndWaitAsync(js2, wordWaitTime);
                    点击屏幕();
                    input_index++;
                }               
            }
            if (strings.Count() > 1)
            {
                ExecuteScriptAndWaitAsync(JavaScriptString.拼多多_点击添加规格类型JS, 1000);
                string js = string.Format(点击并选择规格2js, strings[1]);
                ExecuteScriptAndWaitAsync(js, wordWaitTime);
                input_index++;
                for (int i = 0; i < param_in.spec2.Count; i++)
                {
                    string js2 = string.Format(输入规格2js, input_index, param_in.spec2[i]);
                    ExecuteScriptAndWaitAsync(js2, wordWaitTime);
                    点击屏幕();
                    input_index++;
                }
            }
            result = WorkResult.WorkSuccess();
        }
        private void 退出当前账号() 
        {
            点击元素_左键(JavaScriptString.拼多多_店铺信息按钮JS, 1000);
            点击元素_左键(JavaScriptString.拼多多_退出当前账号JS, 1000);
        }
        private string 获取用户名()
        {
            string js = @"(function(){
               return document.getElementsByClassName('user-name-text')[0].textContent
        })() ";
            string result = EvaluateScriptAsync(js);
            return result;
        }
        private void 规格与库存()
        {
            LogHelper.WriteLog($"规格与库存");
            设置元素居中2(JavaScriptString.拼多多_点击添加规格类型JS);
            点击元素_左键(JavaScriptString.拼多多_点击添加规格类型JS, 1000);
            string 点击规格1js = @"document.getElementsByClassName(""goods-spec-row"")[0].getElementsByClassName(""IPT_input_5-148-0"")[0]";
            string 选择规格1js = @"getElementByText('li','{0}')";
            string 点击规格2js = @"document.getElementsByClassName(""goods-spec-row"")[1].getElementsByClassName(""IPT_input_5-148-0"")[0];";
            string 选择规格2js = @"getElementByText('li','{0}')";
            string 输入规格1js = @"document.getElementsByClassName(""spec-input"")[{0}].getElementsByTagName(""input"")[0]";
            string 输入规格2js = @"document.getElementsByClassName(""spec-input"")[{0}].getElementsByTagName(""input"")[0]";
            string[] strings = param_in.specifications.Split('-');
            int input_index = 0;
            if (strings.Count() > 0)
            {
                string 点击_js = string.Format(点击规格1js, strings[0]);
                string 选择_js = string.Format(选择规格1js, strings[0]);
                点击元素_左键(点击_js, wordWaitTime);
                点击元素_JS(选择_js, wordWaitTime);
                WaitWebBrowserAsync(1000);
                for (int i = 0; i < param_in.spec1.Count; i++)
                {
                    string js2 = string.Format(输入规格1js, input_index );
                    点击元素_输入(js2, param_in.spec1[i], wordWaitTime);
                    //点击屏幕();
                    input_index++;
                }
            }
            if (strings.Count() > 1)
            {
                点击元素_左键(JavaScriptString.拼多多_点击添加规格类型JS, 1000);
                string 点击_js = string.Format(点击规格2js, strings[1]);
                string 选择_js = string.Format(选择规格2js, strings[1]);
                点击元素_左键(点击_js, wordWaitTime);
                点击元素_JS(选择_js, wordWaitTime);
                WaitWebBrowserAsync(1000);
                input_index++;
                for (int i = 0; i < param_in.spec2.Count; i++)
                {
                    string js2 = string.Format(输入规格2js, input_index, param_in.spec2[i]);
                    点击元素_输入(js2, param_in.spec2[i],wordWaitTime);
                    //点击屏幕();
                    input_index++;
                }
            }
            result = WorkResult.WorkSuccess();
        }

        private void 规格与库存2() 
        {
            LogHelper.WriteLog($"规格与库存2");
            //找到规格表格元素
            string 声明speclist变量js = @"var speclistele=document.getElementsByClassName('sku-list')[0].getElementsByTagName('tbody')[0].getElementsByTagName('tr')";
            ExecuteScriptAndWaitAsync(声明speclist变量js, 100);

            string 设置speclist变量js = @"var specinput=speclistele[{0}].getElementsByTagName('input')[{1}];setInputValue(specinput,'{2}');";
            string 上传预览图js = @"speclistele[{0}].getElementsByClassName('sku-preview-img')[0]";
            foreach (Materialfile item in param_in.materialFile)
            {
                if (item.materialType=="sku")
                {
                    for (int i = 0; i < item.specList.Count; i++)
                    {
                        string js = string.Format(设置speclist变量js, i, 0, item.specList[i].stockNum);
                        ExecuteScriptAndWaitAsync(js, wordWaitTime);
                        string js2 = string.Format(设置speclist变量js, i, 1, item.specList[i].price);
                        ExecuteScriptAndWaitAsync(js2, wordWaitTime);
                        string js3 = string.Format(设置speclist变量js, i, 2, item.specList[i].singlePrice);
                        ExecuteScriptAndWaitAsync(js3, wordWaitTime);
                        string js4 = string.Format(设置speclist变量js, i, 3, item.specList[i].skuCode);
                        ExecuteScriptAndWaitAsync(js4, wordWaitTime);
                        string js7 = string.Format(上传预览图js, i);
                        设置元素居中2(js7);
                        点击元素_左键(js7, wordWaitTime);
                        上传图片(new List<string>() { item.specList[i].imageName } );
                    }
                }
            }
            string 设置参考价格js = @"document.getElementById('market_price').getElementsByTagName('input')[0];"; 
            string 清空参考价格js = @$"var ele={设置参考价格js}; setInputValue(ele,'')";
            设置元素居中(设置参考价格js);
            ExecuteScriptAndWaitAsync(清空参考价格js,1000);
            点击元素_输入(设置参考价格js, param_in.goodsReferencePrice,wordWaitTime);
            string 设置满减折扣js = @"document.getElementById('batch_discount').getElementsByTagName('input')[0];";
            点击元素_输入(设置满减折扣js, param_in.fullDiscount, wordWaitTime);
            result = WorkResult.WorkSuccess();
        }
        private void 上传图片(List<string> img_path)
        {
            LogHelper.WriteLog($"进入上传图片模块");
            SetUploadFilePath(img_path);
            点击元素_左键(JavaScriptString.拼多多_本地上传按钮JS, pictureWaitTime);
            点击屏幕();
            WaitWebBrowserAsync(200);
            点击元素_左键(JavaScriptString.拼多多_选择图片按钮JS, wordWaitTime);
            等待上传执行完毕();
            点击元素_左键(JavaScriptString.拼多多_确认上传完毕按钮JS, 1000);
            result = WorkResult.WorkSuccess();
        }
        private void 服务与承诺() 
        {
            LogHelper.WriteLog($"服务与承诺");
            string 设置发货时间js = @"document.getElementById('shipment_limit_second').getElementsByClassName('RD_input_5-138-0')[{0}]";
            string js = string.Empty;

            if (param_in.shipmentTime=="当日发货")
            {
                 js=string.Format(设置发货时间js, 0);
            }
            if (param_in.shipmentTime == "24小时")
            {
                js = string.Format(设置发货时间js, 1);
            }
            if (param_in.shipmentTime == "48小时")
            {
                js = string.Format(设置发货时间js, 2);
            }
            设置元素居中(js);
            //填写发货时间
            点击元素_左键(js, 500,true);
            //展开修改
            点击元素_左键(JavaScriptString.拼多多_展开修改JS, 1000);
            //选择其他模板
            点击元素_左键(JavaScriptString.拼多多_选择其他模板JS, 1000);
            点击内容("service.cost_template_id");
            填写内容并选取("service.cost_template_id",param_in.freightTemplate);
            result = WorkResult.WorkSuccess();
        }
        private void 提交或保存() 
        {
            LogHelper.WriteLog($"提交或保存");
            if (param_in.isDraft == 1)
            {
                LogHelper.WriteLog($"提交草稿");
                设置元素居中2(JavaScriptString.拼多多_保存为草稿JS);
                点击元素_左键(JavaScriptString.拼多多_保存为草稿JS, wordWaitTime);
            }
            else 
            {
                LogHelper.WriteLog($"正式提交");
                设置元素居中2(JavaScriptString.拼多多_提交并上架JS);
                点击元素_左键(JavaScriptString.拼多多_提交并上架JS, wordWaitTime);
            }

            result = WorkResult.WorkSuccess();
        }
        private void 判断发布商品最终成功() 
        {
            for (int i = 0; i < 10; i++)
            {
                string result_res = EvaluateScriptAsync(JavaScriptString.拼多多_判断提交结束JS);
                LogHelper.WriteLog($"正式提交结果判断：{result_res}");
                if (result_res == "True")
                {
                    var uri = new Uri(GetChromiumWebBrowser().Address);
                    NameValueCollection collection = HttpUtility.ParseQueryString(uri.Query);
                    result = WorkResult.WorkSuccess(collection["goods_id"]);
                    return;
                }
                WaitWebBrowserAsync(1000);
            }
            result = WorkResult.WorkFailed("判断提交是否成功超时");
        }
        private bool Is快捷选择品类按钮()
        {
            string result = EvaluateScriptAsync(JavaScriptString.拼多多_获取是否有快捷品类JS);
            if (result == "True")
            {
                return true;
            }
            return false;
        }
        private bool Is快捷选择品类是否被点击按钮()
        {
            string result = EvaluateScriptAsync(JavaScriptString.拼多多_快捷品类是否被点击JS);
            if (result == "True")
            {
                return true;
            }
            return false;
        }

        private bool 填写内容并选取(string id, string content)
        {
            string js_element = @"document.getElementById('{0}').getElementsByTagName('input')[0];";
            string js = string.Format(js_element, id);
            点击元素_输入(js, content, 1000);            
            if (Is选项存在(content))
            {
                string js_select = @"getElementByText('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_左键(js3, wordWaitTime);
            }
            else
            {
                return false;
            }

            return true;
        }       
        private bool 填写内容(string id, string content)
        {
            string js_base = @"var ele=document.getElementById('{0}').getElementsByTagName('input')[0];setInputValue(ele,'{1}');";
            string js = string.Format(js_base, id, content);
            ExecuteScriptAndWaitAsync(js, 1000);
            return true;
        }
        private void 点击内容(string id)
        {
            string js_base = @"document.getElementById('{0}').getElementsByTagName('input')[0]";
            string js = string.Format(js_base, id);
            点击元素_左键(js);
        }
        private bool Is选项存在(string content)
        {
            string js_check = @" (function(){
                return getElementByText('li','"+ content+@"')!=null;
            })() ";
            string result = EvaluateScriptAsync(js_check);
            if (result == "False")
            {
                return false;
            }
            return true;
        }
        private void 选取( string content)
        {
            string js_base2 = @"getElementByText('li','{0}')";
            string js2 = string.Format(js_base2, content);
            点击元素_左键(js2);
        }
        private void 等待上传执行完毕() 
        {
            for (int i = 0; i < 50; i++)
            {
                string result = EvaluateScriptAsync(JavaScriptString.拼多多_判断是否上传完毕JS);
                if (result == "0")
                {
                    WaitWebBrowserAsync(500);
                    
                }
                else
                {
                    WaitWebBrowserAsync(2000);
                    return;
                }
            }
        }
        

    }
}
